package com.basics.organization.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.basics.api.request.organization.EditOrganizationReq;
import com.basics.organization.entity.CyOrganizationPermission;
import com.basics.organization.mapper.CyOrganizationPermissionMapper;
import com.basics.organization.service.CyOrganizationPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 分组权限 服务实现类
 * </p>
 *
 * @author WangWei
 * @since 2025-03-09
 */
@Service
public class CyOrganizationPermissionServiceImpl extends ServiceImpl<CyOrganizationPermissionMapper, CyOrganizationPermission> implements CyOrganizationPermissionService {

    @Override
    public List<EditOrganizationReq.GroupPermission> selectGroupPermissionList(String groupId){
        List<EditOrganizationReq.GroupPermission> permissionList = new ArrayList<>();
        List<CyOrganizationPermission> permissions = list(new QueryWrapper<CyOrganizationPermission>()
                .eq("group_id", groupId));
        if(CollectionUtils.isNotEmpty(permissions)){
            permissions.forEach(v->{
                EditOrganizationReq.GroupPermission permission = new EditOrganizationReq.GroupPermission();
                permission.setPermission(v.getPermission());
                permissionList.add(permission);
            });
        }
        return permissionList;
    }
}
